package com.wltt.product.frfront.service;

import com.wltt.product.frfront.mapper.SwingTypeMapper;
import com.wltt.product.frfront.model.ResultData;
import com.wltt.product.frfront.model.po.SwingTypePO;
import com.wltt.product.frfront.model.vo.AllFormulaRSP;
import com.wltt.product.frfront.model.vo.AllSwingTypeRSP;
import com.wltt.product.frfront.service.base.BaseServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;


/**
 * @ClassName: SwingTypeServiceImpl
 * @Description: 摆动类型 逻辑服务类<br/>
 * 不做业务校验，参数校验统一放到前置的Service中
 * @Date: 2025-07-03 18:01:51
 * @Author yanggl
 */
@Service(value = "swingTypeService")
public class SwingTypeServiceImpl extends BaseServiceImpl<SwingTypePO, Long> implements SwingTypeService {

    private SwingTypeMapper swingTypeMapper;

    //构造方法
    public SwingTypeServiceImpl(SwingTypeMapper swingTypeMapper) {
        super(swingTypeMapper);
        this.swingTypeMapper = swingTypeMapper;
    }

    /**
     * 查询所有摆动类型
     *
     * @return
     */
    @Override
    public ResultData allSwingType() {
        List<SwingTypePO> swingTypePOList = swingTypeMapper.queryAll();
        List<AllSwingTypeRSP> rsps = Optional.ofNullable(swingTypePOList).orElse(new ArrayList<>())
                .stream().map(po -> {
                    AllSwingTypeRSP rsp = new AllSwingTypeRSP();
                    BeanUtils.copyProperties(po, rsp);
                    return rsp;
                }).collect(Collectors.toList());
        return ResultData.success(rsps);
    }
}